package com.addressbook.tests;

import java.io.File;
import java.io.FileReader;
import java.util.Properties;
import java.util.Random;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;

import com.addressbook.fw.ApplicationManager;

public class TestBase {

	public static ApplicationManager app;

	@BeforeTest
	public void setUp() throws Exception {
		String configFile = System.getProperty("configFile",
                "application.properties");
		Properties properties = new Properties();
		properties.load(new FileReader(new File(configFile)));
		app = ApplicationManager.getInstance();
        app.setProperties(properties);
	}

	@AfterTest
	public void tearDown() throws Exception {
//		app.stop();
	}

	public String generationRandomString() {
		Random rnd = new Random();

		if (rnd.nextInt(3) == 0) {
			return "";
		} else {
			return " " + rnd.nextInt();
		}
	}

	protected String generateRandomString(String basis) {
		Random rnd = new Random();
		if (rnd.nextInt(5) == 0) {
			return "";
		} else {
			return basis + rnd.nextInt();
		}
	}
}